package bz.ziro.kanbe.controller.mng.text;

import java.util.Date;
import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

import bz.ziro.kanbe.bean.TextData;
import bz.ziro.kanbe.model.SiteText;
import bz.ziro.kanbe.util.KeyFactory;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * テキストの追加
 * @author Administrator
 */
public class AddController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(AddController.class.getName());

    @Override
    public Navigation run() {

        SiteText text = new SiteText();
        //データを設定
        BeanUtil.copy(request, text);

        //作成者情報を取得
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        text.setCreateDate(new Date());
        text.setCreator(user);

        Key key = KeyFactory.allocateTextKey();
        text.setKey(key);
        Datastore.put(text);

        TextData.refreshTextMap();
        return null;
    }
}
